using System.Collections.Generic;
using System.Linq;

namespace LocalOverride.Fiddler.Store
{
    public class UrlValidator : IValidator
    {
        private readonly IEnumerable<IValidator> validators;
        public UrlValidator(MappingEntry mappingEntry)
        {
            validators = new List<IValidator>
                             {
                                 new UrlRequiredValidator(mappingEntry),
                                 new UrlValidUriValidator(mappingEntry)
                             };
        }
        
        public ValidationResult Validate()
        {
            ValidationResult returnResult = ValidationResult.Valid;

            foreach (var validator in validators)
            {
                var result = validator.Validate();
                if (!result.IsValid)
                {
                    returnResult = result;
                    break;
                }
            }

            return returnResult;
        }
    }
}